﻿using AutoMapper;
using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class UpdaterabbitsCommandHander : IRequestHandler<UpdaterabbitsCommand, ApiResult<object>>
    {
        public readonly IRepistory<Product> _productRepistory;
        public readonly IMapper _mapper;
        public UpdaterabbitsCommandHander(IRepistory<Product> productRepistory, IMapper mapper)
        {
            _productRepistory = productRepistory;
            _mapper = mapper;
        }
        /// <summary>
        /// 商品修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<ApiResult<object>> Handle(UpdaterabbitsCommand request, CancellationToken cancellationToken)
        {
             ApiResult<object> apiResult = new ApiResult<object>();
            var result = _productRepistory.GetAll().FirstOrDefault(x => x.ProductId == request.ProductId);
            result.BatchId = request.BatchId;
            result.FirmName = request.FirmName;
            result.KeepSafe = request.KeepSafe;
            result.Permission = request.Permission;
            result.ProductClassId= request.ProductClassId;
            result.Full=result.Full;
            result.Images=result.Images;
            result.Updatedate =DateTime.Now;
            result.Updateor = "";
            _productRepistory.Update(result);
            apiResult.code = Renum.修改成功;
            apiResult.Message = Renum.修改成功.ToString();
            apiResult.Data = result;
            return Task.FromResult(apiResult);
        }
    }
}
